/**
 * 
 */

var api=frameElement.api, W=api.opener;
var initForm = function(obj){
	$('#_form_repayment_log_default_').form({
		url :'sys/LoanExt/addOrUpdateLoanRepaymentLog',
		onBeforeLoad : function(param){
			$.messager.progress();
		},
		onLoadSuccess : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
		},
		onLoadError : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
			$.messager.alert('提示', "加载内容失败,请重新刷新页面/联系管理员", "error");
		},
		onSubmit : function(param) {
			if (!$(this).form("validate")) {
				$.messager.alert('提示', "提交的选项中,有错误内容,请检查", "error");
				return false;
			}
			obj.attr('disabled','disabled');
			$.messager.progress();
		},
		success : function(data) {	
			$.messager.progress("close");
			obj.removeAttr('disabled');
			var jd = eval('(' + data + ')');
			if(!!!jd){
				$.messager.alert('提示', "未知异常", "error");
				return false;
			}
			if(jd.state!=200){
				$.messager.alert('提示', jd.message, "error");
				return false;
			}
			//清除按钮加样式
			$.dialog.alert('操作成功!',function(){
				api.close();
				//top._do_goto_right('jsp/loan/loan_repayment_detail_edit.jsp?id='+repaymentLogDetailId+'&loanId='+loanId+'&repaymentId='+repaymentId);
			});
		}
	});
};

var resetRepaymentLog = function(){
   $('#submit_repayment_log').removeAttr('disabled');
   $("#_form_repayment_log_default_").form()[0].reset();
   $('#repaymentLogLoanId').val(loanId);
   $('#repaymentLogDetailId').val(repaymentLogDetailId);
   $('#repaymentId').val(repaymentId);
   $('#repaymentLogId').val('');
};




$(function(){
	initForm($('#submit_repayment_log'));
	
	$('#repayType').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Close_Account_Mode_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	$('#payType').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Transaction_Mode_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	$('#payBankName').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Client_Bank_Name_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	if(_is_not_empty(_param_id)){
		$("#_form_repayment_log_default_").form('load', 'sys/LoanRepaymentLog/findByPk?pks=' + _param_id);
	}
	$('input[name="confirm_button"]').click(function(){
		$('#_form_repayment_log_default_').submit();
		$('#submit_repayment_log').attr('disabled','disabled');
	});
	
});
